home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / msdos / all_dir / ad.c next >
C/C++ Source or Header  |  1991-10-18  |  5KB  |  192 lines

  1. /************************************************************************
  2. *   ディレクトリ移動プログラム
  3. *   使用法 : AD
  4. *************************************************************************
  5. */
  6. #include <direct.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11. #include "vramput.h"
  12. void far int24h(void);
  13.  
  14. #define ERR     ( -1 )                  /* エラー 時の リターン・コード   */
  15. #define NOERR   0
  16. #define PATHLEN     ( 3 + 64 )         /* パス の長さ ( "d:\" + パス )   */
  17.  
  18. union   REGS inregs,outregs;
  19. struct  SREGS segregs;
  20.  
  21. char    dirname[768][PATHLEN];
  22. int     dircount=0;
  23.  
  24. int main(int,char **);
  25. void srch_dir( char *);
  26.  
  27. int attr = _A_SUBDIR;                  /* 検索属性     */
  28.  
  29. int main( argc, argv )
  30. int  argc;
  31. char *argv[];
  32. {
  33.     static char rootdir[] = "?:\\";
  34.     char schdir[ PATHLEN ];            /* 検索ディレクトリ          */
  35.     int ch;
  36.  
  37.     _harderr( int24h );                /* int 24h ハンドラ の設定     */
  38.  
  39.     title();
  40.     printv("**** 少々お待ち下さい。****",47,27,12);
  41.  
  42.     for (ch = 'A'; ch <= 'P'; ch++ ) {
  43.         rootdir[ 0 ] = ( char )ch;
  44.         strcpy( schdir, rootdir );
  45.         srch_dir( schdir );           /* ディレクトリ テーブル作成 */
  46.     }
  47.     change_dir();                     /* ディレクトリ変更 */
  48. }
  49.  
  50. void srch_dir(register char schdir[])
  51. {
  52.     struct find_t dta;
  53.     char schpath[ PATHLEN ];
  54.  
  55.     strcpy( schpath, schdir );         /* 検索ディレクトリ セット */
  56.     strcat( schpath, "*.*" );
  57.     if ( _dos_findfirst( schpath, _A_SUBDIR, &dta ) == 0 ) {
  58.     if ( strlen(schdir) == 3 ){
  59.         strcpy(dirname[dircount++],schdir);
  60.     }
  61.     do {
  62.         if ( dta.attrib & _A_SUBDIR ) {
  63.         if ( dta.name[ 0 ] == '.' )
  64.             continue;
  65.         strcpy( schpath, schdir );
  66.         strcat( schpath, dta.name );
  67.         strcpy(dirname[dircount++],schpath );
  68.         strcat( schpath, "\\" );
  69.         srch_dir( schpath );
  70.         }
  71.     } while ( _dos_findnext( &dta ) == 0 );
  72.     }
  73. }
  74.  
  75. void far int24h()
  76. {
  77.     _hardresume( _HARDERR_FAIL );
  78. }
  79.  
  80. dsp(int gyou,int iro,char *moji)
  81. {
  82.     printv(moji,iro,0,gyou+1);
  83. }
  84. title()
  85. {
  86.     cls(1);
  87.     printv("--ディレクトリ変更 (AD)  V1.0 -- Copyright(c) 1991 H/NAKAMURA -----------------------",15,0,0);
  88.     printv("-- \x1E/\x1Fで選択 スペースで内容表示 リタ-ンで決定 ESCで中止 ------------------------------",15,0,23);
  89. }
  90. change_dir()
  91. {
  92.     int keyin,i,top=0,act=0,bot=0,acto=0,actd=0;
  93.     char buf[80];
  94.  
  95.     color(7);
  96.     title();
  97.     csr(0);
  98.  
  99.     dircount--;
  100.     bot = dircount>21 ? 21:dircount;
  101.  
  102.     for(i=0;i<=bot;i++){
  103.         dsp(i,7,dirname[top+i]);
  104.     }
  105.     dsp(0,42,dirname[top]);
  106.     act=0;acto=-1;
  107.  
  108.     for(;;){
  109.         if(acto != act && acto > -1)
  110.             dsp(acto,7,dirname[actd]);
  111.  
  112.         acto = act;actd = top+act;
  113.         dsp(act,42,dirname[top+act]);
  114.  
  115.         keyin = getch();
  116.  
  117.         switch(keyin){
  118.             case 0x1F: if ((act < 21) && top+act < dircount){
  119.                              acto=act;actd=top+act;act++;break;
  120.                          }
  121.                          else if ((act == 21) && (top+act < dircount)){
  122.                              dsp(act,7,dirname[top+act]);
  123.                              acto=21;actd=top+act;top++;upscrol();break;
  124.                          }
  125.                          else if (top+act == dircount){
  126.                              putch('\x07');
  127.                              dsp(act,42,dirname[dircount]);
  128.                              break;
  129.                          }
  130.                          else break;
  131.             case 0x1E:   if (act > 0 && top+act < dircount){
  132.                              acto=act;actd=top+act;act--;break;
  133.                          }
  134.                          else if (act > 0 && top+act == dircount){
  135.                              dsp(act,7,dirname[dircount]);acto=act;actd=top+act;act--;break;
  136.                          }
  137.                          else if (act == 0  && top > 0){
  138.                              dsp(act,7,dirname[top+act]);
  139.                              acto=0;actd=top+act;top--;dnscrol();break;
  140.                          }
  141.                          else putch('\x07');break;
  142.             case 0x20: back_color(0);color(7);cls(1);locate(1,1);sprintf(buf,"DIR %s /P",dirname[top+act]);system(buf);
  143.                        color(1);puts("どれかキーを押して下さい");getch();
  144.                        title();
  145.                        for(i=0;i<=bot;i++){
  146.                            dsp(i,7,dirname[top+i]);
  147.                        }
  148.                        acto=-1;
  149.                        break;
  150.             case 0x0D: move_dir(dirname[top+act]);back_color(0);color(7);cls(1);csr(1);exit(0);
  151.             case 0x1B: back_color(0);color(7);cls(1);csr(1);exit(-1);
  152.             default  : break;
  153.         }
  154.     }
  155. }
  156.  
  157. upscrol()
  158. {
  159.     inregs.h.ah = 0x1A;
  160.     inregs.h.al = 0x00;
  161.     inregs.x.cx = 1;
  162.     inregs.h.dh = 2;
  163.     inregs.h.dl = 1;
  164.     inregs.h.bh = 23;
  165.     inregs.h.bl = 80;
  166.     int86(0x91,&inregs,&outregs);
  167.     locate(1,23);printf("\x1B[K");
  168. }
  169.  
  170. dnscrol()
  171. {
  172.     inregs.h.ah = 0x1A;
  173.     inregs.h.al = 0x01;
  174.     inregs.x.cx = 1;
  175.     inregs.h.dh = 2;
  176.     inregs.h.dl = 1;
  177.     inregs.h.bh = 23;
  178.     inregs.h.bl = 80;
  179.     int86(0x91,&inregs,&outregs);
  180.     locate(1,2);printf("\x1B[K");
  181. }
  182.  
  183. int move_dir( register char dir[] )        /* changeディレクトリ */
  184. {
  185.     unsigned dstdrv;
  186.     unsigned num;
  187.     if(chdir( dir ) != 0) printf("%s err",dir);
  188.     dstdrv = toupper( dir[ 0 ] ) - 'A' + 1;
  189.     _dos_setdrive( dstdrv, &num );
  190. }
  191.  
  192.